const { app, router, pool } = require("../connect");

// 获取项目类型列表
app.get('/study/getProjectTypeList', function(req, res){
    let sql = `select * from study_project_type;`;
    pool.getConnection((err, conn) => {
        if(err) throw err;
        conn.query(sql, (_err, _data) => {
            if(_err) throw _err;
            res.json({
                code: 200,
                data: _data,
                message: "查询成功"
            })
        })
        
        pool.releaseConnection(conn);
    })
})

// 获取指定项目类型下的项目列表
app.get("/study/getProjectList", function(req, res){
    const { projectType } = req.query;
    let sql = `select * from study_project where projectType = '${projectType}';`;
    pool.getConnection((err, conn) => {
        if(err) throw err;
        conn.query(sql, (_err, _data) => {
            if(_err) throw _err;
            res.json({
                code: 200,
                data: _data,
                message: "查询成功"
            })
        })
        pool.releaseConnection(conn);
    })
})

module.exports = router;